/**
 *  @file Stream.h
 */
#ifndef _STREAM_H_
#define _STREAM_H_

#include "../common/BaseObject.h"
#include "../collections/ArrayT.h"

namespace cppflib
{

namespace io
{

/**
 *  Base interface for read/write stream
 */
class _DLLAPI Stream : public BaseObject
{
protected:
   Stream() { }
public:
   //! seek origin
   typedef enum _seekorigin 
   {
      S_BEGIN,
      S_CUR,
      S_END
   } seekorigin_t ;


   virtual ~Stream() { }

   virtual void Close() = 0;
   virtual void Flush() = 0;
   /**
    *  @return number of bytes that can be read without blocking
    */
   virtual sz_t CanReadNoBlocking() { return 0; }
   virtual int Read(collections::ArrayByte &buffer) = 0;
   virtual int Read(collections::ArrayByte &buffer, int offset, int count) = 0;
   virtual int Read() = 0;
   virtual i64_t Seek(i64_t offset, seekorigin_t origin) = 0;
   virtual int Write(collections::ArrayByte &buffer) = 0;
   virtual int Write(collections::ArrayByte &buffer, int offset, int count) = 0;
   virtual bool Write(u8_t val) = 0;

};

/**
 *  Read only stream
 */
class _DLLAPI ReadStream : public Stream
{
protected:
   ReadStream() { }

public:
   virtual ~ReadStream() { }

   /**** these are not valid for a read only stream ****/
   virtual void Flush() { }
   virtual int Write(collections::ArrayByte &buffer) { return 0; }
   virtual int Write(collections::ArrayByte &buffer, int offset, int count) { return 0; }
   virtual bool Write(u8_t val) { return false; }   
};


} // end of namespace io

} // end of namespace cppflib

#endif

